//
//  MCXiaJiWageContractTableViewCell.m
//  TLYL
//
//  Created by MC on 2017/11/1.
//  Copyright © 2017年 TLYL01. All rights reserved.
//


#import "MCXiaJiWageContractTableViewCell.h"
#import "MCDataTool.h"
#import "MCContractMgtTool.h"
#import "MCMineInfoModel.h"

@interface MCXiaJiWageContractTableViewCell()

@property(nonatomic,strong) UIButton * DayWagesProportion;
@property(nonatomic,strong) UIButton * UserName;
//@property(nonatomic,strong) UIButton * Rebate;
//@property(nonatomic,strong) UIButton * State;

@property(nonatomic,strong)UIButton * caoZuo;

@end

@implementation MCXiaJiWageContractTableViewCell
#pragma mark View creation & layout

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createUI];
    }
    return self;
}

-(void)setBtn:(UIButton *)btn WithColor:(UIColor*)color andFont:(UIFont*)font andAlignment:(UIControlContentHorizontalAlignment)alignment andTitle:(NSString *)title{
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=font;
    [btn setTitle:title forState:UIControlStateNormal];
    btn.contentHorizontalAlignment = alignment;
    [self  addSubview:btn];
}
-(void)createUI{
    
    self.backgroundColor=[UIColor whiteColor];
    
    //    用户名：lulu                  返点：1960
    //    比   例:  1.2%日结           状态：已签约
    _UserName =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_UserName WithColor:RGB(46, 46, 46) andFont:[UIFont boldSystemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"加载中..."];
    [_UserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left).offset(18);
        make.width.mas_equalTo(250);
        make.height.mas_equalTo(15);
    }];
    
    
    _DayWagesProportion =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_DayWagesProportion WithColor:RGB(46, 46, 46) andFont:[UIFont systemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@" 加载中..."];
    [_DayWagesProportion mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-15);
        make.left.equalTo(self.mas_left).offset(18);
        make.right.equalTo(self.mas_right).offset(-50);
        //        make.width.mas_equalTo(250);
        make.height.mas_equalTo(15);
    }];
    
    //    _Rebate =[[UIButton alloc]initWithFrame:CGRectZero];
    //    [self setBtn:_Rebate WithColor:RGB(46, 46, 46) andFont:12 andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"返点：加载中..."];
    //    [_Rebate mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(self.mas_top).offset(15);
    //        make.left.equalTo(self.mas_left).offset((G_SCREENWIDTH-26)-100);
    //        make.width.mas_equalTo(100);
    //        make.height.mas_equalTo(15);
    //    }];
    //
    //
    //    _State =[[UIButton alloc]initWithFrame:CGRectZero];
    //    [self setBtn:_State WithColor:RGB(46, 46, 46) andFont:12 andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"状态：加载中..."];
    //    [_State mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.bottom.equalTo(self.mas_bottom).offset(-15);
    //        make.left.equalTo(self.mas_left).offset((G_SCREENWIDTH-26)-100);
    //        make.width.mas_equalTo(100);
    //        make.height.mas_equalTo(15);
    //    }];
    
    _caoZuo =[[UIButton alloc]initWithFrame:CGRectZero];
    [self setBtn:_caoZuo WithColor:RGB(46, 46, 46) andFont:[UIFont systemFontOfSize:12] andAlignment:UIControlContentHorizontalAlignmentLeft andTitle:@"【操作】"];
    [_caoZuo setTitleColor:RGB(255,109,154) forState:UIControlStateNormal];
    [_caoZuo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.right.equalTo(self.mas_right).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
    }];
    
    [_caoZuo addTarget:self action:@selector(action_caoZuo:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}

-(void)action_caoZuo:(UIButton* )btn{
    
    if (self.xiaJiblock) {
        self.xiaJiblock();
    }
}

-(void)setIsAllowSign:(BOOL)isAllowSign{
    if (isAllowSign) {
        _caoZuo.hidden=NO;
    }else{
        _caoZuo.hidden=YES;
    }
}

- (void)setDataSource:(MCGetSubDaywagesNewDataContractListModel *)dataSource{
    _dataSource = dataSource;
    
    //    用户名：lulu                  返点：1960
    //    比   例:  1.2%日结           状态：已签约
    
    
    NSString * State = StateDic[dataSource.State][0];
    if ([State isEqualToString:@"未签约"]) {
        [_DayWagesProportion setTitle:[NSString stringWithFormat:@"%@，%@",[self GetShowBetRebate:dataSource.Rebate],State] forState:UIControlStateNormal];
    }else{
        //         [_DayWagesProportion setTitle:[NSString stringWithFormat:@"%@，【%@】的日结，%@",[self GetShowBetRebate:dataSource.Rebate],[MCContractMgtTool getPercentNumber:dataSource.DayWagesProportion],State] forState:UIControlStateNormal];
        
        [_DayWagesProportion setTitle:[NSString stringWithFormat:@"%@，%@，%@",[self GetShowBetRebate:dataSource.Rebate],dataSource.DayWageStandard,State] forState:UIControlStateNormal];
        
    }
    
    
    [_UserName setTitle:[NSString stringWithFormat:@"%@",dataSource.UserName] forState:UIControlStateNormal];
    
    
    
}

+(CGFloat)computeHeight:(id)info{
    return 70+10;
}


-(NSString * )GetShowBetRebate:(NSString *)Rebate{
    NSString * str = [[NSUserDefaults standardUserDefaults] objectForKey:MerchantMinRebate];
    float fRebate = ([Rebate floatValue] - [str floatValue]) / 20.0;
    return [NSString stringWithFormat:@"%@~%.1f",Rebate,fRebate];
}

@end





































